//
//  EvaluateViewController.m
//  rrqs
//
//  Created by 朱耀春 on 2019/5/3.
//  评论

#import "EvaluateViewController.h"
#import "EvaluateChildViewController.h"
#import "SGPagingView.h"

@interface EvaluateViewController ()

<SGPageTitleViewDelegate,
SGPageContentScrollViewDelegate>

@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentScrollView *pageContentCollectionView;

@end

@implementation EvaluateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupPageView:@[@"全部",@"满意",@"不满意"]];

}

- (void)setupPageView:(NSArray *)titleArr {

    SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
    configure.titleSelectedColor = kY_color;
    configure.indicatorColor     = kY_color;
    configure.titleColor         = kB_color;
    
    _pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44) delegate:self titleNames:titleArr configure:configure];
    self.pageTitleView.backgroundColor = kWhiteColor;
    [self.view addSubview:_pageTitleView];
    //添加子控制器
    NSMutableArray * childArr = [NSMutableArray array];
    for (int i = 0 ; i < titleArr.count; i ++) {
        EvaluateChildViewController * VC = NewFunctionStoryboard(@"EvaluateChildViewController");
        
        VC.numBlock = ^(NSDictionary * _Nonnull numDict) {
            [_pageTitleView resetTitleWithIndex:0 newTitle:[NSString stringWithFormat:@"全部(%@)",numDict[@"all_num"]]];
            [_pageTitleView resetTitleWithIndex:1 newTitle:[NSString stringWithFormat:@"满意(%@)",numDict[@"good_num"]]];
            [_pageTitleView resetTitleWithIndex:2 newTitle:[NSString stringWithFormat:@"不满意(%@)",numDict[@"bad_num"]]];
        };
        VC.type = [NSString stringWithFormat:@"%d",i + 1];
         [childArr addObject:VC];
    }
    
    
    CGFloat ContentCollectionViewHeight = kMainScreenHeight - CGRectGetMaxY(_pageTitleView.frame) - 64;
    self.pageContentCollectionView = [[SGPageContentScrollView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_pageTitleView.frame), self.view.frame.size.width, ContentCollectionViewHeight) parentVC:self childVCs:childArr];
    _pageContentCollectionView.delegatePageContentScrollView = self;
    [self.view addSubview:_pageContentCollectionView];
//    [self add];
}
//-(void)add{
//    [_pageTitleView resetTitleWithIndex:0 newTitle:@"dfsdfs"];
//}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentCollectionView setPageContentScrollViewCurrentIndex:selectedIndex];
}

- (void)pageContentScrollView:(SGPageContentScrollView *)pageContentScrollView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex{
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
    
}


@end
